<template>
  <a-popconfirm
    :title="title"
    @confirm="handleSubmit(downloadIds)"
    okText="是"
    cancelText="否"
  >
    <a href="#">删除</a>
  </a-popconfirm>
</template>

<script>
  import { remove } from '@/api/music/download'

  export default {
    props: {
      downloadIds: {
        type: String,
        default () {
          return ''
        }
      }
    },
    data () {
      return {
        title: '确定要删除这' + this.downloadIds.split(',').length + '条记录吗？'
      }
    },
    watch: {
      downloadIds: function (val) {
        this.title = '确定要删除这' + val.split(',').length + '条记录吗？'
      }
    },
    methods: {
      handleSubmit (downloadIds) {
        remove({ 'downloadIds': downloadIds })
          .then(res => {
            if (res.data.message !== 'error') {
              this.$emit('ok')
            } else {
              this.$message.error('操作失败！')
            }
          })
      }
    }
  }
</script>
